# Contributor: Will Sinatra <wpsinatra@gmail.com>
# Maintainer: Pegah Bahramiani <pb.bahramiani@gmail.com>
pkgname=lua-lapis
_rockname="${pkgname#lua-}"
pkgver=1.9.0
pkgrel=0
pkgdesc="A web framework for Lua/MoonScript supporting OpenResty or http.server"
url="https://leafo.net/lapis/"
license="MIT"
arch="all"
depends="
	lua-ansicolors
	lua-cjson
	lua-date
	lua-etlua
	lua-filesystem
	lua-loadkit
	lua-lpeg
	lua-mimetypes
	lua-ossl
	lua-pgmoon
	lua-socket
"
makedepends="luarocks"
options="!check" # Test dependencies not available
source="$_rockname-$pkgver.tar.gz::https://github.com/leafo/$_rockname/archive/v$pkgver.tar.gz
	lapis-5.1"
builddir="$srcdir/$_rockname-$pkgver"
_luaversions="5.1"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev luarocks$_v"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

build() {
	local lver; for lver in $_luaversions; do
	msg "Building for Lua $lver..."
	luarocks-$lver \
		--deps-mode=none \
		LUA_INCDIR="$(pkg-config --variable=includedir lua$lver)" \
		LUA_LIBDIR="$(pkg-config --variable=libdir lua$lver)" \
		make --tree="./build" \
		"$_rockname-dev-1.rockspec"
	rm "./build/lib/luarocks/rocks-$lver/manifest"
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="
		lua$lver
		lua$_v-ansicolors
		lua$_v-cjson
		lua-date
		lua$_v-etlua
		lua$_v-filesystem
		lua$_v-loadkit
		lua$_v-lpeg
		lua$_v-mimetypes
		lua$_v-ossl
		lua$_v-pgmoon
		lua$_v-socket
"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	install -Dm 755 "$srcdir/lapis-$lver" "$subpkgdir/usr/bin/lapis"
	local path; for path in "lib/luarocks/rocks-$lver" "share/lua/$lver"; do
	mkdir -p "$subpkgdir/usr/${path%/*}"
	mv "$builddir/build/$path" "$subpkgdir/usr/$path/"
	done
}

sha512sums="
a83681a6b1e65c25bf9372d704ca9640e751a1594c75ca7682f2ca75e6ce7e0438f22eb43a1ffebd9e7cdabab3489809d786b38e406a1156eb3c8d0901ad1d22  lapis-1.9.0.tar.gz
c4be44e42089e9c99aff2c092a2654b4b7f3814cbc2036c2d0c43742302760be189bd00072584433c78bcee25bfd37a0ced0f62da0f0d27d04e52f3b64a4e33e  lapis-5.1
"
